package com.cloudauth.core.intercepter;

import com.cloudauth.core.vo.User;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;

/**
@description 使用@Feign注解时 需要配置本bean 为configuration
 封装请求头部参数
@author wbs
**/
@Configuration
public class FeignOAuth2RequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //TODO 引入项目时请封装具体业务参数 此处仅适用于demo
        User user = UserContextHolder.currentUser();
        requestTemplate.header("x-user-id",user.getUserId());
        requestTemplate.header("x-user-name",user.getUserName());
        requestTemplate.header("x-user-serviceName",user.getUserId());

    }
}
